//----------------------------------Include-------------------------------------
#include <stdint.h>
#include "mcu.h"
#include "glbvar.h"
//------------------------------------------------------------------------------

//-----------------------------------Macro--------------------------------------
//------------------------------------------------------------------------------

//--------------------------------Static Var------------------------------------
static uint32_t    src_clk;
static uint32_t    clk_div;
static uint32_t    req_freqHz;
static uint32_t    period_cnt;
//------------------------------------------------------------------------------

//--------------------------------Public Func-----------------------------------
void mcu_delay_10ms(uint32_t ms10)
{
  uint64_t  t;
  t = igu64_tick_10ms;
  while( t + ms10 > igu64_tick_10ms );
}

void mcu_init_tim1(void)
{
//periph clock
  
//timer base
  src_clk    = mcu_get_hclk();
  clk_div    = 1;
  req_freqHz = 100;       //Hz
  period_cnt = (src_clk/clk_div)/req_freqHz;

  TMR1_TimerInit(period_cnt);

//interrupt
  TMR1_ITCfg(ENABLE, TMR0_3_IT_CYC_END);
  PFIC_EnableIRQ(TMR1_IRQn);
  
//enable
  TMR1_Enable();
}
//------------------------------------------------------------------------------

//------------------------------------ISR---------------------------------------
__INTERRUPT
__HIGH_CODE
void TMR1_IRQHandler(void)
{
  if(TMR1_GetITFlag(TMR0_3_IT_CYC_END)){
    TMR1_ClearITFlag(TMR0_3_IT_CYC_END);
#if 1
    //imcu_digit_input();
    igu64_tick_10ms++;
#endif
  }
}
//------------------------------------EOF---------------------------------------









